package 递归;

import java.io.File;

public class 读取目录 {
    public static void main(String[] args){
        String fs= "C:\\Users\\User\\JAVA\\01";
        function(fs);
    }
    public static void  function(String fs){
        File file = new File(fs);
        File[] fl =  file.listFiles();
//        String[] rootname = fs.split("[\\\\]");
//        System.out.println(String.valueOf(rootname));
        for (int i=0;i<fl.length;i++) {
            if(i==fl.length-1)
            {System.out.println(" └"+fl[i].toString().substring(fs.length()+1));}
            else{
                if (i!=0) System.out.print(" │");
                System.out.println(" ├"+fl[i].toString().substring(fs.length()+1));}
            if (new File(fl[i].toString()).isDirectory())
            {
                if(i==fl.length-1)
                {
                    for (int aa=0;aa<fl.length-1;aa++){
                        System.out.print("  ");
                    }
                    function(fl[i].toString());
                }else{
                    for (int aa=0;aa<fl.length-1;aa++){
                        System.out.print(" │");
                    }
                    function(fl[i].toString());
                }

            }
        }
        return;
    }

}
